package work;

import complexity.Stack;

public class BracketsMatchTest {
    public static void main(String[] args) {
        String str = "(()一二三四())";
        boolean match = getMatch(str);
        System.out.println(str+"中的括号是否匹配"+match);
    }
    public static boolean getMatch(String str){
        char[] chars = str.toCharArray();
        Stack<String> stack = new Stack<>();
        for (int i = 0; i < chars.length; i++) {
            if(chars[i]=='('){
                stack.push(String.valueOf(chars[i]));
            }else if (chars[i]==')'){
                String pop = stack.pop();
                if (pop==null){
                    return false;
                }
            }
        }
        if (stack.size()!=0){
            return false;
        }
        return true;
    }
}
